package com.example.analysis.service.impl;

import com.example.analysis.entity.Major;
import com.example.analysis.mapper.MajorDao;
import com.example.analysis.service.MajorService;
import com.example.analysis.utils.Response;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class MajorServiceImpl implements MajorService {
    @Resource
    private MajorDao MajorDao;


    @Override
    public Response<Major> insert(Major aMajor) {
        try {
            MajorDao.insert(aMajor);
            return new Response<>(true, "Insert success", null);
        } catch (Exception e) {
            return new Response<>(false, "Insert failed: " + e.getMessage(), null);
        }
    }

    @Override
    public Response<Major> getById(String MajorId) {
        Major aMajor = MajorDao.selectByPrimaryKey(MajorId);
        if (aMajor != null) {
            return new Response<>(true, "Success", aMajor);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }

    @Override
    public Response<Major> getByName(String MajorName) {
        Major aMajor = MajorDao.selectByName(MajorName);
        if (aMajor != null) {
            return new Response<>(true, "Success", aMajor);
        } else {
            return new Response<>(false, "Administration not found", null);
        }
    }
}
